// Copyright 2018 The Flutter team. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('flutter demo'),
        ),
        body: HomePage(),
      ),
      theme: ThemeData(primarySwatch: Colors.yellow),
    );
  }
}

//自定义有状态组件
class HomePage extends StatefulWidget {
  HomePage({Key? key}) : super(key: key);

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  List list = [];

  @override
  Widget build(BuildContext context) {
    return ListView(children: <Widget>[
      Column(
        children: this.list.map((value) {
          return ListTile(
            title: Text(value),
          );
        }).toList(),
      ),
      SizedBox(
        height: 20,
      ),
      RaisedButton(
        onPressed: () {
          setState(() {
            this.list.add('新增数据1');
            this.list.add('新增数据2');
          });
        },
        child: Text("按钮"),
      )
    ]);
  }
}
